package com.ming.easyDevelop.controller;

import com.ming.easyDevelop.controller.base.BaseController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import com.ming.easyDevelop.service.ProductsService;
import com.ming.easyDevelop.controller.base.ValidListBean;
import javax.validation.Valid;
import com.ming.easyDevelop.entity.po.Products;
import com.ming.easyDevelop.entity.vo.ResponseVo;
import com.ming.easyDevelop.entity.query.ProductsQuery;
import java.util.List;
/**
 * @Description  Controller API
 * @Author ming
 * @Date 2024/07/10
 */
@RequestMapping("/api/products")
@RestController
public class ProductsController extends BaseController {
	@Resource
	private ProductsService productsService;

	@RequestMapping("/list")
	public ResponseVo getDataList(ProductsQuery query){
		return getSuccessResponseVo(this.productsService.findListByParam(query));
	}
	@PostMapping("/add")
	public ResponseVo add(@Valid @RequestBody Products bean){
		this.productsService.add(bean);
		return getSuccessResponseVo(null);
	}

	@PostMapping("/addOrUpdate")
	public ResponseVo addOrUpdate(@Valid @RequestBody Products bean){
		this.productsService.addOrUpdate(bean);
		return getSuccessResponseVo(null);
	}

	@PostMapping("/addBatch")
	public ResponseVo addBatch(@RequestBody ValidListBean<Products> list){
		this.productsService.addBatch(list.getData());
		return getSuccessResponseVo(null);
	}

	@PostMapping("/addOrUpdateBatch")
	public ResponseVo addOrUpdateBatch(@RequestBody ValidListBean<Products> list){
		this.productsService.addOrUpdateBatch(list.getData());
		return getSuccessResponseVo(null);
	}

	/**
	 * 根据ProductID查询
	 */
	@GetMapping("/productID")
	public ResponseVo getByProductID(Integer productID){
		return getSuccessResponseVo(this.productsService.getByProductID(productID));
	}

	/**
	 * 根据ProductID更新
	 */
	@PutMapping("/productID")
	public ResponseVo updateByProductID(@Valid Products bean, Integer productID){
		this.productsService.updateByProductID(bean,productID);
		return getSuccessResponseVo(null);
	}

	/**
	 * 根据ProductID删除
	 */
	@DeleteMapping("/productID")
	public ResponseVo deleteByProductID(Integer productID){
		this.productsService.deleteByProductID(productID);
		return getSuccessResponseVo(null);
	}

	/**
	 * 根据ProductNameAndCategoryID查询
	 */
	@GetMapping("/productNameAndCategoryID")
	public ResponseVo getByProductNameAndCategoryID(String productName, Integer categoryID){
		return getSuccessResponseVo(this.productsService.getByProductNameAndCategoryID(productName, categoryID));
	}

	/**
	 * 根据ProductNameAndCategoryID更新
	 */
	@PutMapping("/productNameAndCategoryID")
	public ResponseVo updateByProductNameAndCategoryID(@Valid Products bean, String productName, Integer categoryID){
		this.productsService.updateByProductNameAndCategoryID(bean,productName, categoryID);
		return getSuccessResponseVo(null);
	}

	/**
	 * 根据ProductNameAndCategoryID删除
	 */
	@DeleteMapping("/productNameAndCategoryID")
	public ResponseVo deleteByProductNameAndCategoryID(String productName, Integer categoryID){
		this.productsService.deleteByProductNameAndCategoryID(productName, categoryID);
		return getSuccessResponseVo(null);
	}

}